<?php
#### PASSWORD HASH #############################################################
function password_hash($password) {
	$base =& Base::getInstance();

	// Calculate password hash
	if ($base->config['session']['method'] == 'plain') $password_hash = $password;
	if ($base->config['session']['method'] == 'md5') $password_hash = md5($password);
	else if ($base->config['session']['method'] == 'sha1' && function_exists('sha1')) $password_hash = sha1($password);
	else if ($base->config['session']['method'] == 'sha1' && function_exists('mhash')) $password_hash = bin2hex(mhash(MHASH_SHA1, $password));
	else die('Your selected password hashing method '.$base->config['session']['method'].' is not supported');

	return $password_hash;
}


#### PASSWORD GENERATOR ########################################################
function password_generator($length = 6) {
	$upper_consonants = 'BCDGKLMNPRST';
	$consonants = 'bcdgklmnprst';
	$vowels = 'aeiou';
	$numbers = '23456789';

	for ($i = 0; $i < 4; $i++) {
		$upper_consonant[$i] = substr($upper_consonants, mt_rand(0, strlen($upper_consonants)-1), 1);
		$consonant[$i] = substr($consonants, mt_rand(0, strlen($consonants)-1), 1);
		$vowel[$i] = substr($vowels, mt_rand(0, strlen($vowels)-1), 1);
		$number[$i] = substr($numbers, mt_rand(0, strlen($numbers)-1), 1);
  	}

	return substr ($upper_consonant[0].$vowel[0].$consonant[0].$vowel[1].$number[0].$upper_consonant[1].$vowel[2].$consonant[2].$vowel[3].$number[1], 0, $length);
}
?>